import { Component, OnInit, ViewChild } from '@angular/core';

import { RemoveTableService } from 'app/public/serve/remove-table/remove-table.service';
import { InitService } from 'app/public/serve/init/init.service';
import { Service } from 'app/server/server';

import { TerminalTableComponent } from './terminal-table/terminal-table.component';

import { terminal } from './terminal.data';

declare var $:any;

@Component({
  selector: 'app-terminal',
  templateUrl: './terminal.component.html',
})

export class TerminalComponent implements OnInit {

  @ViewChild("table") table : TerminalTableComponent;

  right: any = { "system" : {}, "terminal" : {} };
  constructor(
    public initService: InitService,
    public removeTableService: RemoveTableService,
    private server :Service
  ) {
    this.right = $.extend(this.right, server.getRight());
  }

  // 侧边栏缩进
  isActive= this.server.isActive;
  ngOnInit() { 
   this.server.eventEmit.subscribe((value: any) => { this.isActive=value; });
   }

  ngDoCheck(){
    this.right = $.extend(this.right, this.server.getRight());
  } 

  /**
   * 分页
   * @param pagination 
   */ 
  _pagination(pagination: Array<any>) {
    terminal.pagination.pageNumber = pagination[0].pageNumber;
    terminal.pagination.pageSize   = pagination[0].pageSize;
    terminal.pagination.naturalNum = (terminal.pagination.pageNumber - 1) * terminal.pagination.pageSize;
    this.table._table();
  }

  /**
   * 检索
   * @param val
   */ 
  _retrieval(val: string) {
    terminal.queryCriteria = val.trim();
    this.table._table();
  }

}